/**
 * 管理初始化
 */
var Config = {
    id: "ConfigTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Config.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'Primary key', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: 'name', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: 'group', field: 'groupName', visible: true, align: 'center', valign: 'middle'},
            {title: 'class path', field: 'classPath', visible: true, align: 'center', valign: 'middle'},
            {title: 'method name', field: 'methodName', visible: true, align: 'center', valign: 'middle'},
            {title: 'Status', field: 'status', visible: true, align: 'center', valign: 'middle'},
            {title: 'crontab', field: 'cron', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Config.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info($.i18n.prop("common.check"));
        return false;
    }else{
        Config.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Config.openAddConfig = function () {
    var index = layer.open({
        type: 2,
        title: $.i18n.prop("common.add.title"),
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/quartz/config_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
Config.openConfigDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: $.i18n.prop("common.edit.title"),
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/quartz/config_update/' + Config.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Config.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/quartz/delete", function (data) {
            Feng.success($.i18n.prop("common.delete.success"));
            Config.table.refresh();
        }, function (data) {
            Feng.error($.i18n.prop("common.delete.failed"));
        });
        ajax.set("configId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
Config.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Config.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Config.initColumn();
    var table = new BSTable(Config.id, "/quartz/list", defaultColunms);
    table.setPaginationType("client");
    Config.table = table.init();
});
